package com.lyw.GeoLocationClient.bean;

import android.content.Context;
import cn.bmob.v3.BmobACL;
import cn.bmob.v3.BmobObject;
import cn.bmob.v3.datatype.BmobGeoPoint;
import cn.bmob.v3.datatype.BmobRelation;
import cn.bmob.v3.listener.SaveListener;
import cn.bmob.v3.listener.UpdateListener;
import com.google.gson.Gson;
import com.lyw.GeoLocationClient.bmob.restapi.BmobApi;
import timber.log.Timber;

import java.io.Serializable;
import java.util.ArrayList;

public class BmobUser extends BmobObject {

	private static final long serialVersionUID = 1L;
	private String UserId;//
	private String channelId;
	private int headIcon;//
	private int geoId;
	private String polId;
	private int pushID;
	private int pushChannel;
	private String name;
	private String unit;
	private String group;
	private String time;
	private String imei;
    private String username;
    private String password;
	private boolean isAdmin;
    private int type = 0;//0:user; 1:group
    private ArrayList<String> tasks;
    private ArrayList<BmobGeoPoint> geofance;

	public BmobUser(String name, String polId, String unit, String group, String imei) {
		this.name = name;
		this.polId = polId;
		this.unit = unit;
		this.group = group;
		this.imei = imei;

        this.getACL().setPublicReadAccess(true);
        this.getACL().setPublicWriteAccess(true);
	}

	String title;

	public int getIconRes() {
		return mIconRes;
	}

	int mIconRes;

	public int getColor() {
		return mColor;
	}

	int mColor;
	boolean active;

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public BmobUser(String title, int iconRes, int color) {
		this.title = title;
		mIconRes = iconRes;
		mColor = color;

        setAcl();

	}

	public BmobUser() {
        setAcl();
    }

    private void setAcl() {
        if (this.getACL() == null) {
            BmobACL acl =  new BmobACL();
            acl.setPublicWriteAccess(true);
            acl.setPublicReadAccess(true);

            setACL(acl);
        } else {
            this.getACL().setPublicReadAccess(true);
            this.getACL().setPublicWriteAccess(true);
        }
    }

	public BmobUser(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

	public int getGeoId() {
		return geoId;
	}

	public void setGeoId(int geoId) {
		this.geoId = geoId;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public String getPolId() {
		return polId;
	}

	public void setPolId(String polId) {
		this.polId = polId;
	}

	public int getPushID() {
		return pushID;
	}

	public void setPushID(int pushID) {
		this.pushID = pushID;
	}

	public int getPushChannel() {
		return pushChannel;
	}

	public void setPushChannel(int pushChannel) {
		this.pushChannel = pushChannel;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getImei() {
		return imei;
	}

	public void setImei(String imei) {
		this.imei = imei;
	}

	public boolean getIsAdmin() {
		return isAdmin;
	}

	public void setIsAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public ArrayList<String> getTasks() {
        return tasks;
    }

    public ArrayList<BmobGeoPoint> getGeofance() {
        return geofance;
    }

    public void setGeofance(ArrayList<BmobGeoPoint> geofance) {
        this.geofance = geofance;
    }


    public void signUp(Context mContext, final SaveListener listener) {
        Timber.d("sign up");
        this.save(mContext, listener);
    }



    @Override
    public String toString() {
        return "BmobUser{" +
                "UserId='" + UserId + '\'' +
                ", name='" + name + '\'' +
                ", unit='" + unit + '\'' +
                ", group='" + group + '\'' +
                ", time='" + time + '\'' +
                ", imei='" + imei + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", isAdmin=" + isAdmin +
                ", type=" + type +
                ", tasks=" + tasks +
                ", geofance=" + geofance +
                ", title='" + title + '\'' +
                ", active=" + active +
                '}';
    }

    public void setTasks(ArrayList<String> tasks) {
        this.tasks = tasks;
    }
}
